package com.example.joblinker.controller;

import com.example.joblinker.common.Result;
import com.example.joblinker.entity.User;
import com.example.joblinker.mapper.UserMapper;
import com.example.joblinker.util.JwtUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/")
public class HomeController {

    @Resource
    private JwtUtil jwtUtil;
    
    @Resource
    private UserMapper userMapper;

    /**
     * 获取用户引导信息
     */
    @GetMapping("/user-guide")
    public Result<Map<String, Object>> getUserGuide(HttpServletRequest request) {
        // 获取当前用户信息
        Long userId = jwtUtil.getUserIdFromRequest(request);
        User user = userMapper.selectById(userId);
        
        if (user == null) {
            return Result.error("用户不存在或未登录");
        }
        
        Map<String, Object> guideInfo = new HashMap<>();
        
        // 根据用户角色提供不同的引导信息
        if (user.getRole() == 0) {
            // 求职者引导
            guideInfo.put("role", "求职者");
            guideInfo.put("steps", new String[]{
                "创建个人简历",
                "搜索感兴趣的职位",
                "投递简历申请职位",
                "等待面试邀请",
                "参加面试"
            });
        } else if (user.getRole() == 1) {
            // 招聘者引导
            guideInfo.put("role", "招聘者");
            
            // 检查是否已关联公司
            boolean hasCompany = user.getCompanyId() != null && user.getCompanyId() > 0;
            
            if (!hasCompany) {
                guideInfo.put("needCompany", true);
                guideInfo.put("nextStep", "创建公司信息");
                guideInfo.put("nextUrl", "/company/create");
            } else {
                guideInfo.put("needCompany", false);
                guideInfo.put("steps", new String[]{
                    "发布招聘职位",
                    "查看职位申请",
                    "筛选合适的候选人",
                    "安排面试",
                    "发送录用通知"
                });
            }
        } else {
            // 管理员引导
            guideInfo.put("role", "管理员");
            guideInfo.put("steps", new String[]{
                "管理用户账号",
                "审核公司信息",
                "审核职位信息",
                "管理系统配置"
            });
        }
        
        return Result.success(guideInfo);
    }
} 